﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class PermisstionDAL : SQLConnection
    {
        #region[Permisstion_GetById]
        public List<Permisstion> Permisstion_GetById(string Id)
        {
            List<Permisstion> list = new List<Permisstion>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_GetById", Opencon()))
            {
                Permisstion obj = new Permisstion();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PermisstionIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        #endregion
        #region[Permisstion_GetByUserId]
        public List<Permisstion> Permisstion_GetByUserId(string UserId)
        {
            List<Permisstion> list = new List<Permisstion>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_GetByUserId", Opencon()))
            {
                Permisstion obj = new Permisstion();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@UserId", UserId));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PermisstionIDataReader(dr));
                    }
                    dr.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Permisstion_GetByTop]
        public List<Permisstion> Permisstion_GetByTop(string Top, string Where, string Order)
        {
            List<Permisstion> list = new List<Permisstion>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_GetByTop", Opencon()))
            {
                Permisstion obj = new Permisstion();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PermisstionIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        #endregion
        #region[Permisstion_GetByAll]
        public List<Permisstion> Permisstion_GetByAll()
        {
            List<Permisstion> list = new List<Permisstion>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_GetByAll", Opencon()))
            {
                Permisstion obj = new Permisstion();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PermisstionIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        #endregion
        #region[Permisstion_Paging]
        public List<Permisstion> Permisstion_Paging(string CurentPage, string PageSize)
        {
            List<Permisstion> list = new List<Permisstion>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_Paging", Opencon()))
            {
                Permisstion obj = new Permisstion();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PermisstionIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        #endregion
        #region[Permisstion_Insert]
        public bool Permisstion_Insert(Permisstion data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_Insert", Opencon()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@GroupNews", data.GroupNews));
                dbCmd.Parameters.Add(new SqlParameter("@UserId", data.UserId));
                dbCmd.Parameters.Add(new SqlParameter("@Permiss", data.Permiss));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Permisstion");
            return true;
        }
        #endregion
        #region[Permisstion_Update]
        public bool Permisstion_Update(Permisstion data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_Update", Opencon()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@GroupNews", data.GroupNews));
                dbCmd.Parameters.Add(new SqlParameter("@UserId", data.UserId));
                dbCmd.Parameters.Add(new SqlParameter("@Permiss", data.Permiss));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Permisstion");
            return true;
        }
        #endregion
        #region[Permisstion_Delete]
        public bool Permisstion_Delete(string UserId)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Permisstion_Delete", Opencon()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@UserId", UserId));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Permisstion");
            return true;
        }
        #endregion

    }
}
